#include "Game.h"
//globals
#include <d3d9.h>
LPDIRECT3D9  g_pDirect3D = NULL;
LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;
//------------------------------
Game::Game(HINSTANCE hInstance)
:
m_pkWindows(NULL),
m_hInstance(hInstance)
{

}
//--------------------------------
Game::~Game()
{

}
//-----------------------------------------
bool Game::StartUp()
{
	//Variable temporal para almacenar el hWnd recibirlo del CreateWindows y 
	//pasarlo a IntiDX (Al implementar Renderer)

	HWND hWnd=NULL;

	m_pkWindows = new Window(m_hInstance);

	if(!m_pkWindows)
		return false;

	m_pkWindows->createWindow(800, 600, hWnd);

	//-----------------------------------------

	g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS PresentParams;
	memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));

	PresentParams.Windowed = TRUE;
	PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;

	g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT,
								D3DDEVTYPE_HAL,
								hWnd,
								D3DCREATE_SOFTWARE_VERTEXPROCESSING,
								&PresentParams,
								&g_pDirect3D_Device);

	if(!OnStartUp())
		return false;
	
	return true;
}
//-----------------------------------------------------------------------------------------------------------------------------------
bool Game::Loop()
{
	g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);


	g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);

	if(OnLoop())
		return true;

	return false;
}
//-------------------------------------------------------------------------------------------------------------------------------------
bool Game::ShutDown()
{
	if(!OnShutDown())
		return false;

	if(m_pkWindows)
	{
		delete m_pkWindows;
		m_pkWindows = NULL;
	}

	if(g_pDirect3D_Device != NULL)
	{
		g_pDirect3D_Device->Release();
		g_pDirect3D_Device = NULL;
	}

	if(g_pDirect3D != NULL)
	{
		g_pDirect3D->Release();
		g_pDirect3D = NULL;
	}

	//pVertexObject->Release();

	return true;
}
//--------------------------------------------------------------------------------------------------------------------------
